package com.simple.cloud.controller;

import com.simple.cloud.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * <h3>springcloud</h3>
 * <p></p>
 *
 * @author : 你的名字
 * @date : 2020-05-19 14:47
 **/
@RestController
@RequestMapping("/consumer")
public class DeptConsumerController {
    //消费者，不应该有service层
    //RestFul RestTemplate...
    //(url, 实体: Map, reponseType)
    @Autowired
    private RestTemplate restTemplate;
//    private static final String REST_URL = "http://localhost:8001";
    private static final String REST_URL = "http://CLOUD-PROVIDE-DEPT";

    @RequestMapping("/get/{id}")
    public Dept get(@PathVariable("id") Long id) {
        Dept forObject = restTemplate.getForObject(REST_URL + "/dept/get/" + id, Dept.class);
        return forObject;
    }

    @RequestMapping("/add")
    public Boolean get(Dept dept) {
        Boolean aBoolean = restTemplate.postForObject(REST_URL + "/dept/add", dept, Boolean.class);
        return aBoolean;
    }

    @RequestMapping("/get/list")
    public List<Dept> getList() {
        List<Dept> forObjects = restTemplate.getForObject(REST_URL + "/dept/get/list", List.class);
        return forObjects;
    }


}
